package com.hz.ys_stock.action;


import com.hz.framework.MyAction.BaseAction;
import com.hz.framework.dao.CommonDao;
import com.hz.framework.util.DateUtil;
import com.hz.framework.util.Numbers;
import com.hz.ys_stock.bean.PresPurchase;
import com.hz.ys_stock.dao.MakingsDao;
import com.hz.ys_stock.dao.PurchaseDao;
import com.hz.ys_stock.dao.SupplierDao;

/**
 * *****************************************************************************
 *               Copyright(c) 2010 by 哈尔滨华泽数码科技有限公司.
 *                       All rights reserved.
 *******************************************************************************
 *     File Name         :  com.hz.ys_stock.action.PurchaseManageAction.java
 *     Description(说明)	: 采购单管理 action
 * -----------------------------------------------------------------------------
 *     No.        Date              Revised by           Description	
 *     			  Jul 29, 2011           韩飞              Created
 *****************************************************************************
 */
public class PurchaseManageAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	private Object pagList = null;
	private PresPurchase pur = new PresPurchase();
	/**
	 * @author 韩飞
	 * @time Nov 19, 2011	
	 * @return
	 * @throws Exception 
	 * 方法功能: 采购单管理
	 */
	public String PurchaseManage() throws Exception {
		boolean selflag = true;
		boolean pagflag = false;
		String rn = "";
		PurchaseDao pd = new PurchaseDao();
		String operate = CommonDao.isnull(request.getParameter("operate"));
//		录入页面进入
		if("inspage".equals(operate)){
//			查询供应商信息
			request.setAttribute("supplist", new SupplierDao().SelSupplierList());
//			查询人员信息
			request.setAttribute("buyerlist", pd.SelBuyer());
//			查询原材料信息
			request.setAttribute("makingslist", new MakingsDao().SelMakings());
			String goodsid = CommonDao.isnull(request.getParameter("goodsid"));
			request.setAttribute("goodsid", goodsid);
			
			request.setAttribute("purchaseid" , new Numbers().getNumbers("P"+DateUtil.getTimek().substring(2, DateUtil.getTimek().length()),"purchaseid","pres_purchase"));
			
			rn = "inspage";
			selflag = false;
		}
//		保存信息
		if("insinfo".equals(operate)){
			pd.DoSavePurchase(pur , request);
			rn = "rect";
			selflag = false;
		}
//		修改页面进入
		if("updpage".equals(operate)){
//			查询供应商信息
			request.setAttribute("supplist", new SupplierDao().SelSupplierList());
//			查询人员信息
			request.setAttribute("buyerlist", pd.SelBuyer());
//			查询原材料信息
			request.setAttribute("makingslist", new MakingsDao().SelMakings());
			
//			查询采购单信息 和 采购物料信息  放到页面中
			pd.SelPurchase_Info(request);
			
			rn = "updpage";
			selflag = false;
		}
//		修改信息
		if("updinfo".equals(operate)){
			pd.UpdPurchase(pur,request);
			rn = "rect";
			selflag = false;
		}
//		重新下单
		if("againpage".equals(operate)){
//			查询供应商信息
			request.setAttribute("supplist", new SupplierDao().SelSupplierList());
//			查询人员信息
			request.setAttribute("buyerlist", pd.SelBuyer());
//			查询原材料信息
			request.setAttribute("makingslist", new MakingsDao().SelMakings());
			request.setAttribute("purchaseid" , new Numbers().getNumbers("P"+DateUtil.getTimek().substring(2, DateUtil.getTimek().length()),"purchaseid","pres_purchase"));
			
//			查询采购单信息 和 采购物料信息  放到页面中
			pd.SelPurchase_Info(request);
			rn = "againpage";
			selflag = false;
		}
//		查看详细进入
		if("selpage".equals(operate)){
			
//			查询采购单信息 和 采购物料信息  放到页面中
			pd.SelPurchase_Info(request);
			rn = "selpage";
			selflag = false;
		}
//		删除信息
		if("delinfo".equals(operate)){
			pd.Del_Purchase(request);
			rn = "rect";
			selflag = false;
		}
		
//		默认列表页面
		if(selflag){
			rn = SUCCESS;
			pagList = pd.SelPurchase(request);
			pagflag = true;
		}
//		配置分页
		if(pagflag){
			doAllSearchList(request, "listinfo", pagList, "jdbc");
		}
		
		return rn;
	}

	public PresPurchase getPur() {
		return pur;
	}

	public void setPur(PresPurchase pur) {
		this.pur = pur;
	}

	
	
}
